package com.temp.controller.admin;

import com.temp.entity.SystemSetting;
import com.temp.result.Result;
import com.temp.service.SystemSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin/system")
@Api(tags = "管理系统设置相关接口")
@Slf4j
@Validated
public class AdminSysSettingController {

    @Autowired
    private SystemSettingService settingService;

    @GetMapping("/query")
    @ApiOperation("获取系统的所有设置")
    @RequiresPermissions("admin:system:query")
    public Result getAllSetting() {
        return Result.success(settingService.list(),"apiMsg.querySuccess");
    }

    @PostMapping("/update")
    @ApiOperation("保存系统的设置")
    @RequiresPermissions("admin:system:update")
    public Result updateSysSetting(@RequestBody List<SystemSetting> list) {
        boolean isSuccess = settingService.updateBatchById(list);

        return isSuccess ? Result.success("apiMsg.optionSuccess") : Result.error("apiMsg.optionError");
    }
}
